import java.util.Deque;
import java.util.LinkedList;

public class MyCircularQueue {

    private int[] queue;
    public int front;
    public int rear;
    int usedSize;
    public MyCircularQueue(int k) {
        queue = new int[k];
    }

    // 入队
    public boolean enQueue(int value) {
        if (isEmpty()){
            queue[front] = value;
            rear = (rear+1) % queue.length;
            usedSize++;
            return true;
        }
        if (isFull()){
            return false;
        }
        queue[rear] = value;
        rear = (rear+1) % queue.length;
        usedSize++;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()){
            return false;
        }
        front = (front+1) % queue.length;
        usedSize--;
        return true;
    }

    public int Front() {
        if (isEmpty()){
            return -1;
        }
        return queue[front];
    }

    public int Rear() {
        if (isEmpty()){
            return -1;
        }
        int index = -1;
        if (rear == 0){
            index = queue.length-1;
        }else{
            index = rear-1;
        }
        return queue[index];
    }

    public boolean isEmpty() {
        if (front == rear && usedSize == 0){
            return true;
        }
        return false;
    }

    public boolean isFull() {
        if (front == rear && usedSize != 0){
            return true;
        }
        return false;
    }
}
